<?php
include_once "../config/config.php";
include_once "../lib/pdodbmanager.php";
include_once "../lib/functions.php";
include_once "../lib/senitize.php";
$pdo_obj=new PDODBMNanager(HOST,DB,USERNAME,PASS);

//$_REQUEST['test_result_id']=2;
if(isset($_REQUEST['test_result_id'])&& $_REQUEST['test_result_id']!="")
{
	$query_result = "select first_name,last_name,test_name,test_results.*,tests.total_marks as max_marks from test_results,users,tests where test_results.id=".$_REQUEST['test_result_id']." and users.id=test_results.user_id and tests.id=test_results.test_id";
	$result_data=$pdo_obj->selectdata($query_result);
	
}
$pdfname=$result_data[0]['first_name']."-".$result_data[0]['last_name']."-attempt-".$result_data[0]['test_attempts']."-result.pdf";
$pdfname=str_ireplace("_","",$pdfname);
?>
<style type="text/css">
table
{
    width:  100%;
    padding:10px;
    
}
</style>
<page>
<br>

<div style="font-size: 22px; font-weight: bold;margin: auto;width:250px;position: relative;border:0px solid"><u>Result Summary</u><br></div><br><br>
<div style="font-size: 15px; font-weight: bold;border:0px solid">Test: <?php echo $result_data[0]['test_name']; ?><br></div><br>
<div style="font-size: 15px; font-weight: bold;border:0px solid">Trainee Name: <?php echo $result_data[0]['first_name']." ".$result_data[0]['last_name']; ?><br></div><br>
<div style="font-size: 15px; font-weight: bold;border:0px solid">Total Marks: <?php echo $result_data[0]['max_marks']; ?><br></div><br>
<div style="font-size: 15px; font-weight: bold;border:0px solid">Total Obtained Marks: <?php echo $result_data[0]['total_marks']; ?><br></div><br>
<div style="font-size: 15px; font-weight: bold;border:0px solid">Status: <?php if($result_data[0]['result_status']==1)echo "Passed"; else echo "Failed"; ; ?><br></div><br>
	<div style="margin: auto;width:300px;position: relative;">-------------------------------------------------------------------</div>			
				
				<table cellspacing="5" cellpadding="5" style="line-height:1.5;">
					<?php
					$query_questions = "select *,questions.answer as correct_answer from  questions,user_test_answers where user_test_answers.test_id=".$result_data[0]['test_id']." and user_test_answers.attempt_number=".$result_data[0]['test_attempts']." and user_test_answers.question_id=questions.id order by user_test_answers.id asc";
					$result_question=$pdo_obj->selectdata($query_questions);
					$count=0;
					$array_sno=array("1"=>"A","2"=>"B","3"=>"C","4"=>"D","5"=>"E");
					for($i=0;$i<count($result_question);$i++)
					{
						$count++;
					?>
					<tr>
						<td valign="top"><b>Question: <?php echo $count; ?></b></td>
						<td style="width:600px"><?php echo $result_question[$i]['question'] ?></td>
					</tr>
					<?php
					if($result_question[$i]['question_image']!="")
					{
						$sizearr=getimagesize("../uploads/questionimages/".$result_question[$i]['question_image']);
					?>
					<tr>
						<td></td>
						<td><img src="<?php echo "../uploads/questionimages/".$result_question[$i]['question_image']; ?>" <?php $height=$sizearr[1]; if($sizearr[1]>300){ $height=300; }else echo $height=$sizearr[1]; ?> style="height:<?php echo $height; ?>px"></td>
					</tr>
					<?php
					}
					?>
					<tr>
						<td><b>Trainee Answer:</b></td>
						<td>
							<?php 
							$display_answer="";
							if($result_question[$i]['skipped']==0)
							{
								//if(stristr($result_question[$i]['answer'],","))
//								{
//									$display_answer="";
//									$expolde_ans=explode(",",$result_question[$i]['answer']);
//									for($u=0;$u<count($expolde_ans);$u++)
//									{
//										for($s=1;$s<=$result_question[$i]['no_of_choices'];$s++)
//										{
//											if($result_question[$i]['option'.$s]==trim($expolde_ans[$u]))
//											{
//												$display_answer.= $array_sno[$s]." (".$expolde_ans[$u]."), ";
//											}
//										}
//									}
//									$display_answer=substr($display_answer,0,strlen($display_answer)-2);	
//									echo $display_answer;
//								}
//								else
//								{
//									for($s=1;$s<=$result_question[$i]['no_of_choices'];$s++)
//									{
//										if($result_question[$i]['option'.$s]==trim($result_question[$i]['answer']))
//										{
//											$display_answer= $array_sno[$s]." (".$result_question[$i]['answer'].")";
//										}
//									}
//								}
								echo $result_question[$i]['answer'];	
								
							}
							else echo "Skipped";
						 ?>
						</td>
					</tr>
					<tr>
						<td><b>Correct Answer:</b></td>
						<td>
						<?php 
							$display_answer="";
							if(stristr($result_question[$i]['correct_answer'],","))
							{
								$expolde_ans=explode(",",$result_question[$i]['correct_answer']);
								for($s=0;$s<count($expolde_ans);$s++)
								{
									$display_answer.=$result_question[$i]['option'.$expolde_ans[$s]].",";
									//$display_answer.=$array_sno[$expolde_ans[$s]]." (".$result_question[$i]['option'.$expolde_ans[$s]]."), ";
								}
								$display_answer=substr($display_answer,0,strlen($display_answer)-1);
							}
							else
							{
								//$display_answer= $array_sno[$result_question[$i]['correct_answer']]." (".$result_question[$i]['option'.$result_question[$i]['correct_answer']].")";
								$display_answer= $result_question[$i]['option'.$result_question[$i]['correct_answer']];
							}
							echo $display_answer;
						 ?>
						
						</td>
					</tr>
					<tr style="border-bottom:1px dashed">
						<td><b>Marks:</b></td>
						<td><?php echo $result_question[$i]['alloted_positive_marks']; ?></td>
					</tr>
					<tr style="border-bottom:1px dashed">
						<td colspan="2">&nbsp;</td>
						
					</tr>
					<?php
					}
					?>
				</table>

	



</page>
